﻿using BLL;
using Entity;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using YunProject.Controllers.Base;

namespace YunProject.Controllers
{
    public class QualityController : BaseController
    {
        BarBLL barBLL;
        QualityBLL quaBLL;
        public QualityController()
        {
            barBLL = new BarBLL();
            quaBLL = new QualityBLL();
        }
        [Authorize]
        public IActionResult NeedCheckList()
        {
            return View();
        }
        [Authorize]
        public IActionResult QualityCheck()
        {
            return View();
        }
        [Authorize]
        public IActionResult CheckRercord()
        {
            return View();
        }
        [HttpPost]
        public JsonResult AddCheckRecords(string datas, string barCode)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl =quaBLL.AddCheckRecords(barCode,datas, userObj["userCode"].ToString());
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult NoCheckData(string barCodes)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl = quaBLL.NoCheckData(barCodes,userObj["userCode"].ToString());
            }
            return Json(rsl);
        }
        [HttpPost]
        public JsonResult GetCheckRecordByCode(string crCode)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            if (userObj != null)
            {
                rsl = quaBLL.GetCheckRecordByCode(crCode);
            }
            return Json(rsl);
        }
        
        [HttpGet]
        public JsonResult getDataList(string page, string limit, string condition, string dataType)
        {
            var rsl = new ReturnResult();
            var userObj = LoginInfo();
            string pageCount = "1";
            string msg = "";
            var datas = new object();
            if (dataType == "ncheckBar")
            {
                rsl = barBLL.getBarCodeList(page, limit, ref pageCount, condition, "", userObj["baseCode"].ToString());
            }
            else if (dataType == "chRl")
            {
                rsl =quaBLL.getCheckRecordList(page, limit, condition, ref pageCount);
            }
            if (rsl.Result)
            {
                datas = rsl.Data;
            }
            else
            {
                msg = rsl.Message;
            }

            var Data = new
            {
                count = pageCount,
                msg = msg,
                code = "0",
                data = datas
            };

            return new JsonResult(Data);
        }
    }
}
